//
//  AlbumSectionHeaderView.m
//  OntheRoadV4
//
//  Created by ZhangYanhua on 14/11/26.
//  Copyright (c) 2014年 EricHuang. All rights reserved.
//

#import "AlbumSectionHeaderView.h"
#import "QWImageMangerConfig.h"

@implementation AlbumSectionHeaderView

- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    
    return self;
}

- (id)initWithFrame:(CGRect)frame
{
    frame = CGRectMake(0.0f, 0.0f, [UIScreen mainScreen].bounds.size.width, 46.0f);
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.backgroundView = ({
            UIView * view = [[UIView alloc] initWithFrame:self.bounds];
            view.backgroundColor = [UIColor colorWithWhite:1.0f alpha:0.9f];
            view;
        });

        _titleLabel = [[UILabel alloc] initWithFrame:CGRectInset(self.bounds, 10.0f, 0.0f)];
        _titleLabel.textColor = [UIColor colorWithRed:85.0/255.0 green:85.0/255.0 blue:85.0/255.0 alpha:1];
        _titleLabel.font = [[QWImageMangerConfig shareInsatnce] customBoldFont];
        _titleLabel.backgroundColor = [UIColor clearColor];
        _titleLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        [self.contentView addSubview:_titleLabel];
        
        _selectAllBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_selectAllBtn setTitleColor:[[QWImageMangerConfig shareInsatnce] mainFontBlueColor] forState:UIControlStateNormal];
        [_selectAllBtn setFrame:CGRectMake(self.bounds.size.width - 48.0f, 0.0f, 48.0f, self.bounds.size.height)];
        [_selectAllBtn setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight];
        [_selectAllBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
        [_selectAllBtn setContentEdgeInsets:UIEdgeInsetsMake(0.0f, 10.0f, 0.0f, 10.0f)];
        [[_selectAllBtn titleLabel] setFont:[[QWImageMangerConfig shareInsatnce] customBoldFont]];
        
        [_selectAllBtn addTarget:self action:@selector(selectAllBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.contentView addSubview:_selectAllBtn];
        
        [self updateSelectButtonWithTitle:QWImagePickerLocalizedString(@"Select", nil)];
    }
    return self;
}

- (void)updateSelectButtonWithTitle:(NSString *)title
{
    [_selectAllBtn setTitle:title forState:UIControlStateNormal];
    
    CGSize btnSz = [_selectAllBtn sizeThatFits:CGSizeMake(self.bounds.size.width, 44.0f)];
    btnSz.width = ceilf(btnSz.width);
    [_selectAllBtn setFrame:CGRectMake(self.bounds.size.width - btnSz.width, 0.0f, btnSz.width, self.bounds.size.height)];
}

- (void)selectAllBtnPressed:(id)sender
{
    if ([self.delegate respondsToSelector:@selector(selectAllBtnPressedInView:)]) {
        [self.delegate selectAllBtnPressedInView:self];
    }
}


@end
